$(function () {
    $("#jqGrid").jqGrid({
        url: '/sys/order/list',
        datatype: "json",
        colModel: [
            { label: '订单号', name: 'orderNum', index: 'orderNum', width: 100, key: true },
            { label: '金额', name: 'amount', index: 'amount', width: 80 },
            { label: '支付方式', name: 'payType', index: 'payType', width: 80 },
            { label: '订单状态', name: 'status', index: 'status', width: 80 },
            { label: '订单描述', name: 'detail', index: 'detail', width: 80 },
            { label: '下单时间', name: 'createDate', index: 'createDate', width: 100 },
            { label: '完成时间', name: 'finishDate', index: 'finishDate', width: 100 }
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "data.list",
            page: "data.currPage",
            total: "data.totalPage",
            records: "data.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    vm.loadApps();
    $("#select_type").change(function (e) {
        var value = $(this).val();
        var urlStr = "";
        if (value == '1'){
            urlStr = "/sys/order/list";
        }else
            urlStr = "/sys/order/list?appId="+value;
        console.log("change",value,urlStr);
        $("#jqGrid").jqGrid("setGridParam",{
            url:urlStr,
            page:1
        }).trigger("reloadGrid");
    });
});

var vm = new Vue({
    el:"#rrapp",
    data:{
        showList:true,
        apps:[]
    },
    methods:{
        loadApps:function () {
            $.ajax({
                url:"/sys/app/list?page=1&limit=1000",
                type:"POST",
                dataType:"JSON",
                success:function (result) {
                    if (result.code == 0){
                        vm.apps = result.data.list;
                    }else
                        alert(result.msg);
                },
                error:function (e) {
                    console.log("error",e);
                    alert("请求失败，请重试")
                }
            })
        },
        query:function () {
            var value = $("#select_type").val();
            var search = $("#searchContent").val();
            var urlStr = "";
            if (value == '1'){
                if (search != null && search.length > 0){
                    urlStr = "/sys/order/list?orderNum="+search;
                }else
                    urlStr = "/sys/order/list";
            }else
                if (search != null && search.length > 0){
                    urlStr = "/sys/order/list?appId="+value+"&orderNum="+search;
                }else
                    urlStr = "/sys/order/list?appId="+value;
            $("#jqGrid").jqGrid("setGridParam",{
                url:urlStr,
                page:1
            }).trigger("reloadGrid");
        },
        info:function () {
            
        }
    }
});